$("#base")[0].attributes[0].value=$("#base")[0].attributes[0].value+user.code;

$("#logout").on("click",function () {
    $.ajax({
        type : 'POST',
        //  url : 'resource/getTree',
        //data:{"ids":JSON.stringify(ids)},
        url:'account/logout',
        dataType:"json",
        /*  contentType: 'application/json',*/
        async:false,
        success : function (da) {
          /*if(  da.status==200 ){
                tf=true;
            }*/
            window.location.href="/erp";
        },
        error: function(data) {
            // layer.msg("获取失败!");
        }
    });
})
$("#passwd").on("click",function () {

    layer.prompt({title: '输入新密码', formType: 2}, function(pass, index){
        var publickey="";
        var encrypt = new JSEncrypt();

            $.ajax({
                type: 'POST',
                datatype: 'text',
                url:  'codec/getPublicKeyString',
                async:false,
                success: function (data) {
                    var obj = data;
                    if (obj.status == 200) {
                        publickey = obj.data;
                        encrypt.setPublicKey(publickey);
                    }
                }
            });

        var tf=false;
       /* var pwd=$("input[name=password]")[0].value;
        var code=$("input[name=code]")[0].value;*/
        var password=encrypt.encrypt(pass);
        var code=user.code;
        $.ajax({
            type : 'POST',
            //  url : 'resource/getTree',
            data:{"code":code,"password":$.md5(pass),"pwd":password},
            url:'account/updateAccount',
            dataType:"json",
            /*  contentType: 'application/json',*/
            async:false,
            success : function (da) {
                if(  da.status==200 ){
                      tf=true;
                  }

            },
            error: function(data) {
                // layer.msg("获取失败!");
            }
        });
        if(tf){
            layer.close(index);
            layer.msg('修改成功');
        }
       /* layer.prompt({title: '随便写点啥，并确认', formType: 2}, function(text, index){
            layer.close(index);
            layer.msg('演示完毕！您的口令：'+ pass +'<br>您最后写下了：'+text);
        });*/
    });

})

getMenu();
//获取菜单
function  getMenu() {
    $.ajax({
        type : 'POST',
        url : 'user/getMenumByUserCode2',
        async:false,
        success : function (obj) {
            //var obj = JSON.parse(data);
            var da=obj.data.list;
            if (obj.status == 200 && da.length > 0){
              var ui=$("#LAY-system-side-menu");
              for (var i=0;i<da.length;i++){
                  var menu=da[i];
                  var li="<li data-name=\"cp_"+(i+1)+"\" class=\"layui-nav-item\">\n" +
                      "<a href=\"javascript:;\" lay-tips=\""+menu.name+"\" lay-direction=\"2\">\n" +
                       getICON(menu.name) +

                      " <cite>"+menu.name+"</cite><span class=\"layui-nav-more\"></span></a>";

                    var list=da[i].list;
                  for(var n=0;n<list.length;n++){
                      var dl="<dl class=\"layui-nav-child\">\n" +
                          "     <dd data-name=\"console\"><a lay-href=\""+list[n].url+"\">"+list[n].name+" </a></dd>\n" +
                          "  </dl>";
                      li=li+dl;
                  }
                    li=li+ " </li>";
                  ui.append(li);
              }

              layui.element.render("nav","layadmin-system-side-menu");


            }
        },
        error: function(data) {
            var obj = JSON.parse(data);
            alert(obj.msg);
        }
    });
}

function getICON(menuName) {
    if(menuName=="系统设置"){
        return "<i class=\"layui-icon layui-icon-engine\"></i> ";
    }
    if(menuName=="基础资料"){
        return "<i  class=\"layui-icon layui-icon-form\"></i>";
    }
    if(menuName=="出口业务"){
        return "<i  class=\"layui-icon layui-icon-release\"></i> ";
    }
    if(menuName=="资金管理"){
        return "<i   class=\"layui-icon layui-icon-rmb\"></i>";
    }
    if(menuName=="仓库管理"){
        return " <i  class=\"layui-icon layui-icon-component\"></i>";
    }
    if(menuName=="数据大屏"){
        return " <i  class=\"layui-icon layui-icon-website\"></i>";
    }
    if(menuName=="其它"){
        return " <i  class=\"layui-icon layui-icon-survey\"></i>";
    }
    return "";

}
